class Solution {
public:
    vector<vector<int>> ans;
    vector<int> subset;

    void backtrack(int n, vector<int>& nums, int start){
        if(subset.size() == n){
            ans.push_back(subset);
            return;
        }

        for(int i = start; i < nums.size(); i++){
            
            subset.push_back(nums[i]);
            backtrack(n, nums, i+1);
            subset.pop_back();
        }
    }

    vector<vector<int>> subsets(vector<int>& nums) {

        ans.push_back(subset);
        int n = nums.size();

        for(int i = 1; i <= n; i++){
            backtrack(i, nums, 0);
        }

        return ans;
    }
};